package com.popcorn.rmsystem.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.rmsystem.dao.RMSystemDAO;
import com.popcorn.rmsystem.model.RMSystemModel;

public class ReservationUpdateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {	
		RMSystemDAO rmsDAO = new RMSystemDAO();
		RMSystemModel rmsModel = new RMSystemModel();
		ActionForward forward= new ActionForward();
		
		int idx = Integer.parseInt(request.getParameter("RMS_IDX"));
		int STARTTIME = Integer.parseInt(request.getParameter("STARTTIME"));
		int ENDTIME = Integer.parseInt(request.getParameter("ENDTIME"));
   		boolean result=false;
   		
   		try{		
   			String HP = request.getParameter("HP1")+
   					'-'+request.getParameter("HP2")+
   					'-'+request.getParameter("HP3");
   			
   			String rDATE = request.getParameter("TRANDATE");
   			String [] DATE = rDATE.split("-");
   			
   			rmsModel.setRMS_IDX(idx);
   			rmsModel.setTEAM_NAME(request.getParameter("TEAM_NAME"));
   			rmsModel.setNAME(request.getParameter("NAME"));
   			rmsModel.setHP(HP);
   			rmsModel.setTRANDATE(DATE[0]+DATE[1]+DATE[2]);
   			rmsModel.setSTARTTIME(STARTTIME);
   			rmsModel.setENDTIME(ENDTIME);
   			rmsModel.setROOMSIZE(request.getParameter("ROOMSIZE"));
	   		result=rmsDAO.modelUpdate(rmsModel);
	   		
	   		if(result==false){
	   			System.out.println("DB 수정 실패");
	   			return null;
	   		}
	   		
		   	System.out.println("DB 수정 성공");		
		   	forward.setRedirect(false);
	   		forward.setPath("RMSDetailDB.bo?idx="+idx);
	   		return forward;
   		
   		}catch(Exception ex){
   			ex.printStackTrace();
   		}
		return null;
		
	}
}
